﻿using System;

[System.Serializable]
public class GameData
{
    private int _BestScore = 0;
    private int _CurrentScore = 0;
    private int _CoinNumber = 0;
    private int _CurrentTargetNumber = 9;
    //private readonly int[,] _ColorNumberArray = new int[6, 9];

    #region Public Parameter
    public bool NoAds { get; set; } = false;
    public bool RateComplete { get; set; } = false;
    public bool IsFirstInGame { get; set; } = false;
    public bool GameFail { get; set; } = false;
    public int CurrentTargetNumber
    {
        get { return _CurrentTargetNumber; }
        set
        {
            if(value > 109)
            {
                _CurrentTargetNumber = value - 100;
            }
            else
            {
                _CurrentTargetNumber = value;
            }
        }
    }
    public int BestScore
    {
        get { return _BestScore; }
        set
        {
            _BestScore = value;
            EventManager2.OnBestScoreChange?.Invoke(_BestScore);
        }
    }
    public int CurrentScore
    {
        get { return _CurrentScore; }
        set
        {
            _CurrentScore = value;
            EventManager2.OnScoreChange?.Invoke(_CurrentScore);
            if (_CurrentScore > BestScore)
            {
                BestScore = _CurrentScore;
            }
        }
    }
    public int CoinNumber
    {
        get { return _CoinNumber; }
        set
        {
            _CoinNumber = value > 0 ? value : 0;
            EventManager2.OnCoinChange?.Invoke(_CoinNumber);
        }
    }
    public int[,] NumberArray { get; set; } = new int[5, 7];
    #endregion

    public GameData(bool noAds, bool rateComplete, bool isFirstInGame,bool gameFail,int currentTarget, int bestScore, int currentScore,
        int coinNumber, int[,] numberArray)
    {
        NoAds = noAds;
        RateComplete = rateComplete;
        IsFirstInGame = isFirstInGame;
        GameFail = gameFail;
        CurrentTargetNumber = currentTarget;
        BestScore = bestScore;
        CurrentScore = currentScore;
        CoinNumber = coinNumber;
        NumberArray = numberArray;
    }
}
